home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue67 / appbars / Unit1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-12-18  |  3.5 KB  |  136 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ShellAPI, StdCtrls;
  8.  
  9. const
  10.   wm_AppBarMessage = wm_User;
  11.  
  12. type
  13.   TForm1 = class(TForm)
  14.     Memo1: TMemo;
  15.     procedure FormCreate(Sender: TObject);
  16.     procedure FormDestroy(Sender: TObject);
  17.     procedure FormShow(Sender: TObject);
  18.     procedure FormActivate(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.     abd: TAppBarData;
  22.     function GetRequestRect: TRect;
  23.     procedure WMAppBarMessage(var Msg: TMessage); message wm_AppBarMessage;
  24.     procedure WMWindowPosChanged(var Msg: TWMWindowPosMsg); message WM_WindowPosChanged;
  25.     procedure WMMoving(var Msg: TMessage); message WM_Moving;
  26.     procedure WMSizing(var Msg: TMessage); message WM_Sizing;
  27.     procedure WMExitSizeMove(var Msg: TMessage); message WM_ExitSizeMove;
  28.     property RequestRect: TRect read GetRequestRect;
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. var
  39.   F: TextFile;
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.   // fill the AppBarData data structure
  46.   abd.cbSize := sizeof(abd);
  47.   abd.hWnd := Handle;
  48.   abd.uCallBackMessage := wm_AppBarMessage;
  49.   abd.uEdge := ABE_BOTTOM;
  50.   abd.rc := RequestRect;
  51.   abd.lParam := 0;
  52.   SHAppBarMessage(ABM_NEW, abd);
  53.  
  54.   // set the initial size and position
  55.   SHAppBarMessage(ABM_QUERYPOS, abd);
  56.   abd.rc.Top := abd.rc.Bottom - Height;
  57.   SHAppBarMessage(ABM_SETPOS, abd);
  58.   SetBounds(abd.rc.Left, abd.rc.Bottom - Height, abd.rc.Right-abd.rc.Left, Height);
  59. end;
  60.  
  61. procedure TForm1.FormDestroy(Sender: TObject);
  62. begin
  63.   SHAppBarMessage(ABM_REMOVE, abd);
  64. end;
  65.  
  66. procedure TForm1.FormShow(Sender: TObject);
  67. begin
  68.   ShowWindow(Application.Handle, SW_HIDE);
  69.   Memo1.Text := DateTimeToStr(Now);
  70. end;
  71.  
  72. procedure TForm1.FormActivate(Sender: TObject);
  73. begin
  74.   SHAppBarMessage(ABM_ACTIVATE, abd);
  75. end;
  76.  
  77. function TForm1.GetRequestRect: TRect;
  78. begin
  79.   // set the requested Rect
  80.   Result.Left := 0;
  81.   Result.Top := Screen.Height - Height;
  82.   Result.Right := Screen.Width;
  83.   Result.Bottom := Screen.Height;
  84. end;
  85.  
  86. procedure TForm1.WMAppBarMessage(var Msg: TMessage);
  87. begin
  88.   // hide when fullscreen apps are displayed
  89.   if Msg.wParam = ABN_FULLSCREENAPP then
  90.     if Msg.lParam <> 0 then Hide else Show;
  91.  
  92.   if Msg.wParam = ABN_POSCHANGED then
  93.   begin
  94.     // fill the AppBarData data structure
  95.     abd.rc := RequestRect;
  96.     SHAppBarMessage(ABM_QUERYPOS, abd);
  97.     abd.rc.Top := abd.rc.Bottom - Height;
  98.     SHAppBarMessage(ABM_SETPOS, abd);
  99.     SetBounds(abd.rc.Left, abd.rc.Bottom - Height, abd.rc.Right-abd.rc.Left, Height);
  100.   end;
  101. end;
  102.  
  103. procedure TForm1.WMWindowPosChanged(var Msg: TWMWindowPosMsg);
  104. begin
  105.   // must send this message to maintain correct Z-order
  106.   SHAppBarMessage(ABM_WINDOWPOSCHANGED, abd);
  107.   inherited;
  108. end;
  109.  
  110. procedure TForm1.WMMoving(var Msg: TMessage);
  111. begin
  112.   PRect(Msg.lParam)^ := abd.rc;
  113.   inherited;
  114. end;
  115.  
  116. procedure TForm1.WMSizing(var Msg: TMessage);
  117. begin
  118.   PRect(Msg.lParam)^ := Rect(Left, PRect(Msg.lParam)^.Top, Width, PRect(Msg.lParam)^.Bottom);
  119.   inherited;
  120. end;
  121.  
  122. procedure TForm1.WMExitSizeMove(var Msg: TMessage);
  123. begin
  124.   abd.rc.Top := abd.rc.Bottom - Height;
  125.   SetBounds(abd.rc.Left, abd.rc.Top, abd.rc.Right-abd.rc.Left, abd.rc.Bottom-abd.rc.Top);
  126.   SHAppBarMessage(ABM_SETPOS, abd);
  127.   inherited;
  128. end;
  129.  
  130. initialization
  131.   AssignFile(F, 'c:\temp\debug.log');
  132.   Rewrite(F);
  133. finalization
  134.   CloseFile(F);
  135. end.
  136.